//
//  VRChooseDateView.m
//  KeepAccount
//
//  Created by Veer on 2017/12/23.
//  Copyright © 2017年 Veer. All rights reserved.
//

#import "VRChooseDateView.h"


@interface VRChooseDateView()

@property (nonatomic, weak) UIDatePicker *datePicker;

@property (nonatomic, strong) NSDateFormatter *formatter;

@end

@implementation VRChooseDateView

- (instancetype)init
{
    if (self = [super init]) {
        
        self.formatter = [[NSDateFormatter alloc] init];
        self.formatter.dateFormat = @"yyyy-MM-dd";
        
        UIDatePicker *datePicker = [[UIDatePicker alloc] init];
        datePicker.datePickerMode = UIDatePickerModeDate;
        datePicker.minimumDate = [self.formatter dateFromString:@"2010-01-01"];
        datePicker.maximumDate = [self.formatter dateFromString:@"2020-12-31"];
        [self.alertView addSubview:datePicker];
        self.datePicker = datePicker;
        [datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(40);
            make.bottom.mas_equalTo(self.alertView);
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-20);
        }];
    }
    return self;
}

#pragma mark - action
- (void)buttonEvent:(UIButton *)sender
{
    [super buttonEvent:sender];
    
    NSDate *selectedDate = self.datePicker.date;
    if (self.sureBlock) {
        self.sureBlock(selectedDate);
    }
    
}

- (void)dealloc
{
    NSLog(@"VRChooseDateView_dealloc");
}

#pragma mark - setter && getter
- (void)setDate:(NSDate *)date
{
    _date = date;
    
    self.datePicker.date = date;
}

@end
